import React, { Component } from "react";
import "./index.css";
export default class Footer extends Component {
  handldCheckall = (event) => {
    this.props.checkAllTodo(event.target.checked);
  };
  handleClear = () => {
    this.props.clearDone();
  };
  render() {
    let { todos } = this.props;
    //总条数
    let allToal = todos.length;
    //已完成的条数
    let doneCount = todos.reduce((pre, item) => {
      return pre + (item.done ? 1 : 0);
    }, 0);
    // console.log(doneCount, "1");
 
    return (
      <div className="todo-footer">
        <label>
          <input
            type="checkbox"
            checked={doneCount === allToal && allToal !== 0 ? true : false}
            onChange={this.handldCheckall}
          />
        </label>
        <span>
          <span>已完成{doneCount}</span> / 全部{allToal}
        </span>
        <button onClick={this.handleClear} className="btn btn-danger">
          清除已完成任务
        </button>
      </div>
    );
  }

}